package util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;

public class ThreadPool {
	
	private Logger log = Logger.getLogger(ThreadPool.class);
	
	private ThreadPool()
	{
		pool = Executors.newCachedThreadPool();
	}
	
	public static class ThreadPoolHolder
	{
		public static ThreadPool instance = new ThreadPool();
	}
	
	public static ThreadPool getInstance()
	{
		return ThreadPoolHolder.instance;
	}
	
	private ExecutorService pool = null;
	
	public boolean execute(Runnable r)
	{
		try
		{
			pool.execute(r);
			return true;
		}
		catch(Exception ex)
		{
			log.error(ex);
			return false;
		}
	}
}
